<?php
if (!defined('APP_ID')) { die('No direct script access allowed'); }

/**
 * Databas gate
 */
class Query {
	const DATA_AUTO = null;
	const DATA_STRING = 'string';
	const DATA_INTEGER = 'integer';
	const DATA_FUNCTION = 'function';
	const DATA_SERIALIZE = 'serialize';
	
	const ORDER_ASC = 'ASC';
	const ORDER_DESC = 'DESC';
	
	const JOIN_INNER = 'INNER JOIN';
	const JOIN_OUTER_LEFT = 'LEFT OUTER JOIN';
	const JOIN_OUTER_RIGHT = 'RIGHT OUTER JOIN';
	
    public static function factory($type = 'select') {
		$driver = ucfirst(trim(strtolower(Config::get('driver', 'database'))));
		$type = ucfirst(trim(strtolower($type)));
		
		$class_name = 'Database_Query_' . $driver . '_' . $type;
		return new $class_name;
    }
	
    public static function data(&$data, $field, $value, $type = self::DATA_AUTO) {
		$tmp = array();
		$tmp['field'] = $field;
		$tmp['value'] = $value;
		$tmp['type'] = $type;
		$data[(string)$field] = $tmp;
    }
}
